<?php
/**
 * Created by PhpStorm.
 * User: mark
 * Date: 18-10-21
 * Time: 下午1:12
 * 监听者 持有事件对象
 */
namespace Event;

abstract class Listener{
  public $event;
  public function __construct(Event $event) {
    $this->event = $event;
  }

  public static function New(string $classSign, Event $event):Listener{
    return new $classSign($event);
  }

  /**
   * @return string 监听者签名
   */
  public function getClassSign(){
    return get_class($this);
  }
  abstract public function handler();
}

class generateTokenListener extends Listener{
  public function __construct(LoginEvent $event) {
    parent::__construct($event);
  }
  public function handler() {
    echo "generateToken success\n";
  }
}

class CountUserNumberListener extends Listener{
  public function __construct(LoginEvent $event) {
    parent::__construct($event);
  }
  public function handler() {
    echo "count user number success\n";
  }
}